#牛牛数据库地址：118.24.3.40 jxz/123456
import pymysql

# 连接数据库
conn=pymysql.connect(host="118.24.3.40",
                user="jxz",
                passwd="123456",
                db="jxz",
                port=3306,
                charset="utf8",
                autocommit=True #自动提交
                     )
#建立游标
cursor=conn.cursor(pymysql.cursors.DictCursor)

#执行sql语句
#show tables;查看当前所有表
#cursor.execute("show tables;")
#cursor.execute('insert into students (name,phone,age,sex) values ("wxy",18500979583,18,"女");')
cursor.execute("select * from students limit 5")

#取字段信息
print(cursor.description)

#提交命令xc
#conn.commit()

#获取sql执行的结果
result=cursor.fetchall()#获取所有的结果
#result=cursor.fetchone()#一次获取一条
# result=cursor.fetchmany(5)#获取n条数据
print(result)



#表数据较多时使用这个
for line in cursor:
    print(line)

#关闭数据库
cursor.close()
conn.close()

import MySQL
check_banlace='select balance from user_wxy,user_account_wxy where user_wxy.id=user_account_wxy.user_id and user_name="wxy123";'
MySQL.execute_sql(check_banlace)
result=cursor.fetchall()